package pl.edu.pw.stud.ltrzaska.mvc.model;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

import org.apache.commons.lang.SystemUtils;
import org.apache.log4j.Logger;

import pl.edu.pw.stud.ltrzaska.mvc.controller.Controller;
import pl.edu.pw.stud.ltrzaska.mvc.view.UserMessage;

public class Model extends AbstractModel {
	public static final String USER_MESSAGES_PROPERTY = "userMessages";
	public static final String POLICY_FILE_PROPERTY = "policyFile";
	public static final String FILESYSTEM_TO_VALIDATE_PROPERTY = "filesystemToValidate";
	public static final String OUTPUT_FILE_PROPERTY = "outputFile";
	
	private static Logger LOGGER = Logger.getLogger(Model.class);
	private File policyFile;
	private File filesystemToValidate;
	private String outputFile;
	private List<UserMessage> userMessages = new LinkedList<UserMessage>();

	public Model() {
		initDefaults();
	}

	private void initDefaults() {
		File projectDir = SystemUtils.getUserDir();
		setFilesystemToValidate(new File(projectDir, "reference-filesystem/projekt"));
		setPolicyFile(new File(getFilesystemToValidate(), "/policy-1.xml"));
	}

	public void setPolicyFile(File policyFile) {
		this.policyFile = policyFile;
	}

	public File getPolicyFile() {
		return this.policyFile;
	}

	public void setFilesystemToValidate(File policyDir) {
		this.filesystemToValidate = policyDir;
	}

	public File getFilesystemToValidate() {
		return this.filesystemToValidate;
	}

	public void addUserMessage(UserMessage userMessage) {
		List<UserMessage> newValue = new LinkedList<UserMessage>(this.getUserMessages());
		newValue.add(userMessage);
		firePropertyChange(Model.USER_MESSAGES_PROPERTY, this.userMessages, newValue);
		this.userMessages = newValue;
	}

	public List<UserMessage> getUserMessages() {
		return userMessages;
	}

	public void setOutputFile(String outputFile) {
		this.outputFile = outputFile;
	}

	public String getOutputFile() {
		return this.outputFile;
	}

}
